package com.yulebaby.callsenter.adapter.selectadpter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yulebaby.callsenter.R;

import java.util.List;

/**
 * Author: Zhangbo
 * Time: 2017/1/17
 */
public class DateLeftAdapter extends BaseAdapter {

    private Context mContext;
    private List<String> list;
    private Holder hoder;

    // 默认第一个图片是选中了的
    private int selectPosition = 0;

    public DateLeftAdapter(Context context, List<String> list) {
        this.mContext = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    public void setSelectItem(int position) {
        this.selectPosition = position;
    }

    public int getSelectItem() {
        return this.selectPosition;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_left_drop_down, null);
            hoder = new Holder(convertView);
            convertView.setTag(hoder);
        } else {
            hoder = (Holder) convertView.getTag();
        }

        hoder.layout.setBackgroundColor(0xFFEBEBEB);
        hoder.textView.setText(list.get(position));
        if (position == selectPosition) {
            hoder.layout.setBackgroundColor(0xFFFFFFFF);
        }
        return convertView;
    }

    private static class Holder {

        private TextView textView;
        private LinearLayout layout;

        public Holder(View view) {
            textView = (TextView) view.findViewById(R.id.tv_select);
            layout = (LinearLayout) view.findViewById(R.id.ll_layout);
        }
    }
}
